﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AF
{
    // 抽象产品族,均有一个Render方法
    public interface IButton
    {
        void Render();
    }
    public interface ITextBox
    {
        void Render();
    }
    public interface IDropDown
    {
        void Render();
    }

    // 黑色主题产品族
    public class DarkButton : IButton
    {
        public void Render() => Console.WriteLine("Dark Theme Button");
    }
    public class DarkTextBox : ITextBox
    {
        public void Render() => Console.WriteLine("Dark Theme TextBox");
    }
    public class DarkDropDown : IDropDown
    {
        public void Render() => Console.WriteLine("Dark Theme DropDown");
    }

    // 白色主题产品族
    public class LightButton : IButton
    {
        public void Render() => Console.WriteLine("Light Theme Button");
    }
    public class LightTextBox : ITextBox
    {
        public void Render() => Console.WriteLine("Light Theme TextBox");
    }
    public class LightDropDown : IDropDown
    {
        public void Render() => Console.WriteLine("Light Theme DropDown");
    }

    // 抽象工厂
    public interface IUIFactory
    {
        IButton CreateButton();
        ITextBox CreateTextBox();
        IDropDown CreateDropDown();
    }

    // 黑色主题工厂
    public class DarkThemeFactory : IUIFactory
    {
        public IButton CreateButton() => new DarkButton();
        public ITextBox CreateTextBox() => new DarkTextBox();
        public IDropDown CreateDropDown() => new DarkDropDown();
    }

    // 白色主题工厂
    public class LightThemeFactory : IUIFactory
    {
        public IButton CreateButton() => new LightButton();
        public ITextBox CreateTextBox() => new LightTextBox();
        public IDropDown CreateDropDown() => new LightDropDown();
    }


    /// <summary>
    /// 建造产品
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            //func1();
            func2_DarkTheme();
            func2_LightTheme();

            Console.ReadKey();
        }

        static void func1()
        {
            Client client = new Client();
            IProduct productA = client.CreateProductA();
            IProduct productB = client.CreateProductB();
            IProduct productC = client.CreateProductC();
            Console.WriteLine(productA);
            Console.WriteLine(productB);
            Console.WriteLine(productC);
        }

        static void func2_DarkTheme()
        {
            var factory = new DarkThemeFactory(); // or LightThemeFactory

            IButton button = factory.CreateButton();
            ITextBox textbox = factory.CreateTextBox();
            IDropDown dropdown = factory.CreateDropDown();

            button.Render();
            textbox.Render();
            dropdown.Render();
        }
        static void func2_LightTheme()
        {
            IUIFactory factory = new LightThemeFactory(); // or LightThemeFactory

            IButton button = factory.CreateButton();
            ITextBox textbox = factory.CreateTextBox();
            IDropDown dropdown = factory.CreateDropDown();

            button.Render();
            textbox.Render();
            dropdown.Render();
        }

    }
}
